home *** CD-ROM | disk | FTP | other *** search
- property button, buttonImage, spriteNum, inOperation, RowNum, ColNum
- global grid, CLRS, pScore, pScoreBox, points, gameOver, ScoreTotal, pScoreBoxTotal, victory, currentStage
-
- on beginSprite me
- inOperation = 0
- button = new(script("direction buttons"), spriteNum)
- buttonImage = sprite(spriteNum)
- RowNum = GetGridRow()
- ColNum = GetGridCol()
- grid[RowNum][ColNum][1] = button
- end
-
- on mouseDown me
- if (buttonImage.member.name = "left") or (buttonImage.member.name = "right") then
- puppetSound(4, member("moveleft-right"))
- else
- if (buttonImage.member.name = "down") or (buttonImage.member.name = "up") then
- puppetSound(4, member("moveup-down"))
- else
- puppetSound(4, member("moveup-down"))
- puppetSound(5, member("moveleft-right"))
- end if
- end if
- if not inOperation then
- if ilk(button, #object) then
- inOperation = 1
- sprite(spriteNum).member = member(sprite(spriteNum).member.name & "2", "direction buttons")
- moveGamePieces(button.getDirection())
- myname = sprite(spriteNum).member.name
- sprite(spriteNum).member = member(chars(myname, 1, myname.char.count - 1), "direction buttons")
- inOperation = 0
- if (CLRS[1] = 0) and (CLRS[2] = 0) and (CLRS[3] = 0) and (CLRS = [4] = 0) and (CLRS[5] = 0) and (CLRS[6] = 0) then
- gameOver = timeout("game won").new(450, #nextStage, me)
- else
- repeat with i = 1 to CLRS.count
- if CLRS[i] = 1 then
- gameOver = timeout("game over").new(450, #endGame, me)
- end if
- end repeat
- end if
- end if
- end if
- end
-
- on moveGamePieces dirOfMove
- if ilk(dirOfMove, #symbol) then
- if dirOfMove = #left then
- posList = []
- repeat with pse = grid[RowNum].findPos([button]) down to 1
- if ilk(grid[RowNum][pse][1], #object) then
- if grid[RowNum][pse][1].script = script("direction buttons") then
- if grid[RowNum][pse][1].spriteNum <> spriteNum then
- exit repeat
- end if
- end if
- else
- if grid[RowNum][pse][1] = #block then
- exit repeat
- end if
- end if
- posList.add(pse)
- end repeat
- posList.sort()
- repeat with piece in posList
- if ilk(grid[RowNum][piece][1], #object) then
- if grid[RowNum][piece][1].script = script("game pieces") then
- if piece > 1 then
- if grid[RowNum][piece - 1][1] = #empty then
- grid[RowNum][piece][1].MoveThis(dirOfMove)
- grid[RowNum][piece - 1][1] = grid[RowNum][piece][1]
- grid[RowNum][piece][1] = #empty
- end if
- end if
- end if
- end if
- end repeat
- posList.deleteAll()
- upYours()
- else
- if dirOfMove = #right then
- posList = []
- repeat with pse = grid[RowNum].findPos([button]) to grid[RowNum].count
- if ilk(grid[RowNum][pse][1], #object) then
- if grid[RowNum][pse][1].script = script("direction buttons") then
- if grid[RowNum][pse][1].spriteNum <> spriteNum then
- exit repeat
- end if
- end if
- else
- if grid[RowNum][pse][1] = #block then
- exit repeat
- end if
- end if
- posList.add(pse)
- end repeat
- posList.sort()
- repeat with piece = posList.count down to 1
- if ilk(grid[RowNum][posList[piece]][1], #object) then
- if grid[RowNum][posList[piece]][1].script = script("game pieces") then
- if piece > 1 then
- if grid[RowNum][posList[piece] + 1][1] = #empty then
- grid[RowNum][posList[piece]][1].MoveThis(dirOfMove)
- grid[RowNum][posList[piece] + 1][1] = grid[RowNum][posList[piece]][1]
- grid[RowNum][posList[piece]][1] = #empty
- end if
- end if
- end if
- end if
- end repeat
- posList.deleteAll()
- upYours()
- else
- if dirOfMove = #up then
- posList = []
- repeat with pse = RowNum down to 1
- if ilk(grid[pse][ColNum][1], #object) then
- if grid[pse][ColNum][1].script = script("direction buttons") then
- if grid[pse][ColNum][1].spriteNum <> spriteNum then
- exit repeat
- end if
- end if
- else
- if grid[pse][ColNum][1] = #block then
- exit repeat
- end if
- end if
- posList.add(pse)
- end repeat
- posList.sort()
- repeat with piece = 1 to posList.count
- if ilk(grid[posList[piece]][ColNum][1], #object) then
- if grid[posList[piece]][ColNum][1].script = script("game pieces") then
- if piece > 1 then
- if grid[posList[piece] - 1][ColNum][1] = #empty then
- grid[posList[piece]][ColNum][1].MoveThis(dirOfMove)
- grid[posList[piece] - 1][ColNum][1] = grid[posList[piece]][ColNum][1]
- grid[posList[piece]][ColNum][1] = #empty
- end if
- end if
- end if
- end if
- end repeat
- upYours()
- else
- if dirOfMove = #down then
- posList = []
- repeat with pse = RowNum to grid.count
- if ilk(grid[pse][ColNum][1], #object) then
- if grid[pse][ColNum][1].script = script("direction buttons") then
- if grid[pse][ColNum][1].spriteNum <> spriteNum then
- exit repeat
- end if
- end if
- else
- if grid[pse][ColNum][1] = #block then
- exit repeat
- end if
- end if
- posList.add(pse)
- end repeat
- posList.sort()
- repeat with piece = posList.count down to 1
- if ilk(grid[posList[piece]][ColNum][1], #object) then
- if grid[posList[piece]][ColNum][1].script = script("game pieces") then
- if piece < grid.count then
- if grid[posList[piece] + 1][ColNum][1] = #empty then
- grid[posList[piece]][ColNum][1].MoveThis(dirOfMove)
- grid[posList[piece] + 1][ColNum][1] = grid[posList[piece]][ColNum][1]
- grid[posList[piece]][ColNum][1] = #empty
- end if
- end if
- end if
- end if
- end repeat
- upYours()
- else
- if dirOfMove = #multi then
- repeat with directiontoGo in [#left, #up, #right, #down]
- if directiontoGo = #left then
- posList = []
- repeat with pse = grid[RowNum].findPos([button]) down to 1
- if ilk(grid[RowNum][pse][1], #object) then
- if grid[RowNum][pse][1].script = script("direction buttons") then
- if grid[RowNum][pse][1].spriteNum <> spriteNum then
- exit repeat
- end if
- end if
- end if
- posList.add(pse)
- end repeat
- posList.sort()
- repeat with piece in posList
- if ilk(grid[RowNum][piece][1], #object) then
- if grid[RowNum][piece][1].script = script("game pieces") then
- if piece > 1 then
- if grid[RowNum][piece - 1][1] = #empty then
- grid[RowNum][piece][1].MoveThis(directiontoGo)
- grid[RowNum][piece - 1][1] = grid[RowNum][piece][1]
- grid[RowNum][piece][1] = #empty
- end if
- end if
- end if
- end if
- end repeat
- posList.deleteAll()
- next repeat
- end if
- if directiontoGo = #up then
- posList = []
- repeat with pse = RowNum down to 1
- if ilk(grid[pse][ColNum][1], #object) then
- if grid[pse][ColNum][1].script = script("direction buttons") then
- if grid[pse][ColNum][1].spriteNum <> spriteNum then
- exit repeat
- end if
- end if
- end if
- posList.add(pse)
- end repeat
- posList.sort()
- repeat with piece = 1 to posList.count
- if ilk(grid[posList[piece]][ColNum][1], #object) then
- if grid[posList[piece]][ColNum][1].script = script("game pieces") then
- if piece > 1 then
- if grid[posList[piece] - 1][ColNum][1] = #empty then
- grid[posList[piece]][ColNum][1].MoveThis(directiontoGo)
- grid[posList[piece] - 1][ColNum][1] = grid[posList[piece]][ColNum][1]
- grid[posList[piece]][ColNum][1] = #empty
- end if
- end if
- end if
- end if
- end repeat
- next repeat
- end if
- if directiontoGo = #right then
- posList = []
- repeat with pse = grid[RowNum].findPos([button]) to grid[RowNum].count
- if ilk(grid[RowNum][pse][1], #object) then
- if grid[RowNum][pse][1].script = script("direction buttons") then
- if grid[RowNum][pse][1].spriteNum <> spriteNum then
- exit repeat
- end if
- end if
- end if
- posList.add(pse)
- end repeat
- posList.sort()
- repeat with piece = posList.count down to 1
- if ilk(grid[RowNum][posList[piece]][1], #object) then
- if grid[RowNum][posList[piece]][1].script = script("game pieces") then
- if piece > 1 then
- if grid[RowNum][posList[piece] + 1][1] = #empty then
- grid[RowNum][posList[piece]][1].MoveThis(directiontoGo)
- grid[RowNum][posList[piece] + 1][1] = grid[RowNum][posList[piece]][1]
- grid[RowNum][posList[piece]][1] = #empty
- end if
- end if
- end if
- end if
- end repeat
- posList.deleteAll()
- next repeat
- end if
- if directiontoGo = #down then
- posList = []
- repeat with pse = RowNum to grid.count
- if ilk(grid[pse][ColNum][1], #object) then
- if grid[pse][ColNum][1].script = script("direction buttons") then
- if grid[pse][ColNum][1].spriteNum <> spriteNum then
- exit repeat
- end if
- end if
- end if
- posList.add(pse)
- end repeat
- posList.sort()
- repeat with piece = posList.count down to 1
- if ilk(grid[posList[piece]][ColNum][1], #object) then
- if grid[posList[piece]][ColNum][1].script = script("game pieces") then
- if piece < grid.count then
- if grid[posList[piece] + 1][ColNum][1] = #empty then
- grid[posList[piece]][ColNum][1].MoveThis(directiontoGo)
- grid[posList[piece] + 1][ColNum][1] = grid[posList[piece]][ColNum][1]
- grid[posList[piece]][ColNum][1] = #empty
- end if
- end if
- end if
- end if
- end repeat
- end if
- end repeat
- upYours()
- end if
- end if
- end if
- end if
- end if
- end if
- testToMatchHor()
- testToMatchVer()
- end
-
- on testToMatchHor me
- repeat with row = 1 to grid.count
- repeat with col = 1 to grid[row].count
- if ilk(grid[row][col][1], #object) then
- if grid[row][col][1].script = script("game pieces") then
- if col <> grid[row].count then
- colorMLIST = []
- repeat with i = col + 1 to grid[row].count
- if ilk(grid[row][i][1], #object) then
- if grid[row][i][1].script = script("game pieces") then
- if grid[row][col][1].myColor = grid[row][i][1].myColor then
- colorMLIST.add(grid[row][i][1])
- xtc = i
- else
- exit repeat
- end if
- else
- exit repeat
- end if
- next repeat
- end if
- exit repeat
- end repeat
- if colorMLIST.count > 0 then
- tempClr = grid[row][col][1].myColor
- repeat with zs = col to xtc
- CLRS[symbol(tempClr)] = CLRS[symbol(tempClr)] - 1
- grid[row][zs][1].getRid()
- grid[row][zs][1] = #empty
- pScore = value(pScore) + points
- ScoreTotal = ScoreTotal + points
- pScoreBoxTotal.text = string(ScoreTotal)
- pScoreBox.text = string(pScore)
- end repeat
- puppetSound(2, member("dissapear"))
- colorMLIST.deleteAll()
- end if
- end if
- end if
- end if
- end repeat
- end repeat
- end
-
- on testToMatchVer me
- repeat with row = 1 to grid.count
- repeat with col = 1 to grid[row].count
- if ilk(grid[row][col][1], #object) then
- if grid[row][col][1].script = script("game pieces") then
- if col <> grid[row].count then
- colorMLIST = []
- repeat with i = row + 1 to grid.count
- if ilk(grid[i][col][1], #object) then
- if grid[i][col][1].script = script("game pieces") then
- if grid[row][col][1].myColor = grid[i][col][1].myColor then
- colorMLIST.add(grid[i][col][1])
- xtc = i
- else
- exit repeat
- end if
- else
- exit repeat
- end if
- next repeat
- end if
- exit repeat
- end repeat
- if colorMLIST.count > 0 then
- tempClr = grid[row][col][1].myColor
- repeat with zs = row to xtc
- CLRS[symbol(tempClr)] = CLRS[symbol(tempClr)] - 1
- grid[zs][col][1].getRid()
- grid[zs][col][1] = #empty
- pScore = value(pScore) + points
- pScoreBox.text = string(pScore)
- ScoreTotal = ScoreTotal + points
- pScoreBoxTotal.text = string(ScoreTotal)
- end repeat
- puppetSound(2, member("dissapear"))
- colorMLIST.deleteAll()
- end if
- end if
- end if
- end if
- end repeat
- end repeat
- end
-
- on endGame me
- gameOver.forget()
- victory = #no
- go("end")
- end
-
- on nextStage me
- gameOver.forget()
- cC = currentStage.char.count
- if value(currentStage.char[cC]) < 5 then
- go(string(value(currentStage.char[cC]) + 1))
- else
- if value(currentStage.char[cC]) = 5 then
- victory = #yes
- go("end")
- end if
- end if
- end
-
- on upYours me
- if (the actorList).count = 0 then
- inOperation = 0
- else
- if (the actorList).count > 0 then
- repeat while (the actorList).count > 0
- updateStage()
- end repeat
- inOperation = 0
- end if
- end if
- end
-
- on GetGridRow me
- if (buttonImage.locV >= 26) and (buttonImage.locV <= 60) then
- return 1
- else
- if (buttonImage.locV >= 60) and (buttonImage.locV <= 95) then
- return 2
- else
- if (buttonImage.locV >= 95) and (buttonImage.locV <= 130) then
- return 3
- else
- if (buttonImage.locV >= 130) and (buttonImage.locV <= 165) then
- return 4
- else
- if (buttonImage.locV >= 165) and (buttonImage.locV <= 200) then
- return 5
- else
- if (buttonImage.locV >= 200) and (buttonImage.locV <= 235) then
- return 6
- else
- if (buttonImage.locV >= 235) and (buttonImage.locV <= 270) then
- return 7
- else
- if (buttonImage.locV >= 270) and (buttonImage.locV <= 305) then
- return 8
- else
- if (buttonImage.locV >= 305) and (buttonImage.locV <= 340) then
- return 9
- else
- if (buttonImage.locV >= 340) and (buttonImage.locV <= 375) then
- return 10
- else
- if (buttonImage.locV >= 375) and (buttonImage.locV <= 410) then
- return 11
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end
-
- on GetGridCol me
- if (buttonImage.locH >= 27) and (buttonImage.locH <= 61) then
- return 1
- else
- if (buttonImage.locH >= 61) and (buttonImage.locH <= 96) then
- return 2
- else
- if (buttonImage.locH >= 96) and (buttonImage.locH <= 131) then
- return 3
- else
- if (buttonImage.locH >= 131) and (buttonImage.locH <= 166) then
- return 4
- else
- if (buttonImage.locH >= 166) and (buttonImage.locH <= 201) then
- return 5
- else
- if (buttonImage.locH >= 201) and (buttonImage.locH <= 236) then
- return 6
- else
- if (buttonImage.locH >= 236) and (buttonImage.locH <= 271) then
- return 7
- else
- if (buttonImage.locH >= 271) and (buttonImage.locH <= 306) then
- return 8
- else
- if (buttonImage.locH >= 306) and (buttonImage.locH <= 341) then
- return 9
- else
- if (buttonImage.locH >= 341) and (buttonImage.locH <= 376) then
- return 10
- else
- if (buttonImage.locH >= 376) and (buttonImage.locH <= 411) then
- return 11
- else
- if (buttonImage.locH >= 411) and (buttonImage.locH <= 447) then
- return 12
- else
- if (buttonImage.locH >= 447) and (buttonImage.locH <= 481) then
- return 13
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end
-